package com.example.wujinapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wujinapi.dao.ContactsDao;
import com.example.wujinapi.dao.FirsttypeDao;
import com.example.wujinapi.entity.Contacts;
import com.example.wujinapi.entity.Firsttype;
import com.example.wujinapi.service.ContactsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Contacts)表服务实现类
 *
 * @author makejava
 * @since 2023-07-20 00:07:35
 */
@Service("contactsService")
public class ContactsServiceImpl extends ServiceImpl<ContactsDao, Contacts> implements ContactsService {

    @Autowired
    private ContactsDao contactsDao;

    @Override
    public void addContacts(Contacts contacts) {
        Contacts Data=contactsDao.selectOne(new QueryWrapper<Contacts>().isNotNull("content"));
        if(Data==null){ //为空才插入新用户
            contactsDao.insert(contacts);
        }else{
            contacts.setId(Data.getId());
            contactsDao.updateById(contacts);
        }
    }

    @Override
    public void updateContacts(Contacts contacts) {
        Contacts fdata=contactsDao.selectOne(new QueryWrapper<Contacts>().eq("id", contacts.getId()));
        if(fdata!=null){
            contacts.setId(fdata.getId());
            contactsDao.updateById(contacts);
        }
    }

    @Override
    public List<Contacts> getContacts() {
        List<Contacts> fdata=contactsDao.selectList(new QueryWrapper<Contacts>().eq("isshow",1));
        return fdata!=null?fdata:null;
    }

    @Override
    public Contacts getContactNotNull() {
        Contacts Data=contactsDao.selectOne(new QueryWrapper<Contacts>().isNotNull("content").eq("isshow",1));
        return Data!=null?Data:null;
    }

    @Override
    public Contacts getContactsById(int contactId) {
        Contacts fdata=contactsDao.selectOne(new QueryWrapper<Contacts>().eq("id", contactId).eq("isshow",1));
        return fdata!=null?fdata:null;
    }
}

